package com.kerrykidz.system.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kerrykidz.common.Constants;
import com.kerrykidz.scminvoicing.dao.model.GblScmPrdCateEntity;
import com.kerrykidz.scminvoicing.service.IScmInvocingProductInfoService;
import com.kerrykidz.system.dao.mapper.CourseEntityMapper;
import com.kerrykidz.system.dao.mapper.KdeBatchEntityMapper;
import com.kerrykidz.system.dao.mapper.KdeVoucherRecEntityMapper;
import com.kerrykidz.system.dao.model.KdeBatchEntity;
import com.kerrykidz.system.dao.model.KdeVerPrdAndPaymentEntity;
import com.kerrykidz.system.dao.model.KdeVoucherEntEntity;
import com.kerrykidz.system.dao.model.KdeVoucherRecEntity;
import com.kerrykidz.system.service.ICourseService;
import com.kerrykidz.system.service.IK3Service;
import com.kerrykidz.system.util.DateUtil;
import com.kerrykidz.system.util.K3Util;
import com.rdp.framework.exception.RDPException;
import com.rdp.util.GenerationUUID;
import com.rdp.util.lang.ObjectUtil;

@Service
public class IK3ServiceImpl implements IK3Service {

	@Autowired
	private KdeBatchEntityMapper kdeBatchEntityMapper;

	@Autowired
	private KdeVoucherRecEntityMapper vrMapper;
	@Autowired
	private CourseEntityMapper courseMapper;
	
	@Autowired
	ICourseService courseService;

	
	@Autowired
	private IScmInvocingProductInfoService productService;
	/**
	 * 获取金蝶对接批次表，分页展示
	 * 
	 * @param kdeBatch
	 * @return
	 * @throws RDPException
	 */
	@Override
	public KdeBatchEntity getKdeBatchList(KdeBatchEntity kdeBatch)
			throws RDPException {
		kdeBatch.setIspaging(true);
		List<KdeBatchEntity> beanList = kdeBatchEntityMapper
				.getKdeBatchList(kdeBatch);
		if (beanList.size() > 0) {
			kdeBatch.setResults(beanList);
		}
		return kdeBatch;
	}

	@Override
	public List<Map<String, Object>> findAddMember(String date) throws RDPException {
		return vrMapper.findAddMember(date);
	}

	/**
	 * K3查询单次票
	 * @param date
	 * @return
	 * @throws RDPException
	 */
	@Override
	public List<Map<String, Object>> findSingleTicket(String date) throws RDPException {
		return vrMapper.findSingleTicket(date);
	}

	@Override
	public List<Map<String, Object>> findAvgMember(String date) throws RDPException {
		return vrMapper.findAvgMember(date);
	}

	@Override
	public List<Map<String, Object>> findRetreatMember(String date) throws RDPException {
		return vrMapper.findRetreatMember(date);
	}

	@Override
	public List<Map<String, Object>> findRecharge(String date) throws RDPException {
		return vrMapper.findRecharge(date);
	}

	@Override
	public List<Map<String, Object>> findRechargeConsume(String date) throws RDPException {
		return vrMapper.findRechargeConsume(date);
	}

	@Override
	public List<Map<String, Object>> findRechargeConsumeRefund(String date) throws RDPException {
		return vrMapper.findRechargeConsumeRefund(date);
	}

	@Override
	public List<Map<String, Object>> findBalanceRefund(String date) throws RDPException {
		return vrMapper.findBalanceRefund(date);
	}

	@Override
	public List<Map<String, Object>> findExpiredBalance(String date) throws RDPException {
		return vrMapper.findExpiredBalance(date);
	}

	@Override
	public List<Map<String, Object>> findPartyPrepay(String date) throws RDPException {
		return vrMapper.findPartyPrepay(date);
	}

	@Override
	public KdeBatchEntity addK3Docking(KdeBatchEntity kde) throws RDPException {
		
		/**凭证内码*/
		List<KdeVoucherRecEntity> kdeVRList = new ArrayList<KdeVoucherRecEntity>();
		
		/**凭证内码记录*/
		List<KdeVoucherEntEntity> kdeEntList = new ArrayList<KdeVoucherEntEntity>();
		
		/**凭证内码记录关联*/
		List<KdeVerPrdAndPaymentEntity> kdeVerPrdList = new ArrayList<KdeVerPrdAndPaymentEntity>();
		List<KdeVerPrdAndPaymentEntity> kdeVerPaymentList = new ArrayList<KdeVerPrdAndPaymentEntity>();
		
		/**获取确认对接时间*/
		Date enterDate = kde.getConfirmTime();
		if(ObjectUtil.isNotNull(enterDate)){
			
			
			String enterDateStr = DateUtil.formatDate("yyyy-MM-dd", enterDate);
			
			/*设置批次*/
			kde.setPkKdebtId(GenerationUUID.getGenerationUUID());
			kde.setSyncStatus(KdeBatchEntity.STATUS_UNSTART);
			/*kde.setSyncDate(new Date());
			kde.setLastSync(new Date());*/
			kde.setTrialCnt(0);
			kde.setModiTime(new Date());
			kdeBatchEntityMapper.insertKdeBatchEntity(kde);
			
			
			/*单次票    收入*/
			List<Map<String,Object>> dcpList = vrMapper.findSingleTicketEnter(enterDateStr);
			if(dcpList != null && dcpList.size() > 0){
				for(Map<String,Object> map : dcpList){
					
					/**jd 表示收入为true  全部为正数   否则为负数*/
					map.put("jd", true);
					map.put("km", "dcp");
					
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}
			
			/*会籍  - 新增会员   收入*/
			List<Map<String,Object>> newMemList = vrMapper.findAddMemberEnter(enterDateStr);
			if(newMemList != null && newMemList.size() > 0){
				for(Map<String,Object> map : newMemList){
					map.put("jd", true);
					map.put("km", "hj-xz");
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}
			
			/*会籍  - 会员费分摊   收入*/
			List<Map<String,Object>> avgMemList = vrMapper.findAvgMemberEnter(enterDateStr);
			if(avgMemList != null && avgMemList.size() > 0){
				for(Map<String,Object> map : avgMemList){
					map.put("jd", true);
					map.put("km", "hj-ft");
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}
			
			/*会籍  - 会员退会   支出*/
			List<Map<String,Object>> retreatMemList = vrMapper.findRetreatMemberEnter(enterDateStr);
			if(retreatMemList != null && retreatMemList.size() > 0){
				for(Map<String,Object> map : retreatMemList){
					map.put("jd", false);
					map.put("km", "hj-th");
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}
			
			/*储值  - 新增储值   收入*/
			List<Map<String,Object>> addRechargeList = vrMapper.findRechargeEnter(enterDateStr);
			if(addRechargeList != null && addRechargeList.size() > 0){
				for(Map<String,Object> map : addRechargeList){
					map.put("jd", true);
					map.put("km", "cz-xz");
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}
			
			/*储值  - 储值销售   收入*/
			List<Map<String,Object>> rechargeConsumeList = vrMapper.findRechargeConsumeEnter(enterDateStr);
			if(rechargeConsumeList != null && rechargeConsumeList.size() > 0){
				for(Map<String,Object> map : rechargeConsumeList){
					map.put("jd", true);
					map.put("km", "cz-xf");
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}
			
			/*储值  - 储值消费退货   支出*/
			List<Map<String,Object>> rechargeConsumeRefundList = vrMapper.findRechargeConsumeRefundEnter(enterDateStr);
			if(rechargeConsumeRefundList != null && rechargeConsumeRefundList.size() > 0){
				for(Map<String,Object> map : rechargeConsumeRefundList){
					map.put("jd", false);
					map.put("km", "cz-xf-th");
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}
			
			/*储值  - 储值消费退货   支出*/
			List<Map<String,Object>> balanceRefundList = vrMapper.findBalanceRefundEnter(enterDateStr);
			if(balanceRefundList != null && balanceRefundList.size() > 0){
				for(Map<String,Object> map : balanceRefundList){
					map.put("jd", false);
					map.put("km", "cz-ye-th");
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}
			
			/*储值  - 过期余额   收入*/
			List<Map<String,Object>> expiredBalanceList = vrMapper.findExpiredBalanceEnter(enterDateStr);
			if(expiredBalanceList != null && expiredBalanceList.size() > 0){
				for(Map<String,Object> map : expiredBalanceList){
					map.put("jd", true);
					map.put("km", "cz-ye-gq");
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}
			
			/*派对团体  - 新增预约   收入*/
			List<Map<String,Object>> partyPrepayList = vrMapper.findPartyPrepayEnter(enterDateStr);
			if(partyPrepayList != null && partyPrepayList.size() > 0){
				for(Map<String,Object> map : partyPrepayList){
					map.put("jd", true);
					map.put("km", "pdtt-yy-xz");
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}
			
			/*课程  新购课程   预收入*/
			List<Map<String,Object>> newCouseMap = courseMapper.getNewCoureseK3(enterDateStr);
			if(newCouseMap != null && newCouseMap.size() > 0){
				for(Map<String,Object> map : newCouseMap){
					/**jd 表示收入为true  全部为正数   否则为负数*/
					map.put("jd", true);
					map.put("km", "kc-xg");
					
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}
			/*课程  签到课程  收入*/
			List<Map<String,Object>> signCouseMap = courseMapper.getSignCoureseK3(enterDateStr);
			if(signCouseMap != null && signCouseMap.size() > 0){
				for(Map<String,Object> map : signCouseMap){
					/**jd 表示收入为true  全部为正数   否则为负数*/
					map.put("jd", true);
					map.put("km", "kc-qd");
					
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}
			
			/*课程  过期课程  收入*/
			List<Map<String,Object>> exceedCouseMap = courseMapper.getExceedCoureseK3(enterDateStr);
			if(exceedCouseMap != null && exceedCouseMap.size() > 0){
				for(Map<String,Object> map : exceedCouseMap){
					/**jd 表示收入为true  全部为正数   否则为负数*/
					map.put("jd", true);
					map.put("km", "kc-gq");
					
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}
			
			/*礼券*/
			/*List<Map<String,Object>> useCouponMap = courseService.findUseCouponK3(enterDateStr);
			if(useCouponMap != null && useCouponMap.size()>0){
				for(Map<String,Object> map : useCouponMap){
					*//**jd 表示收入为true  全部为正数   否则为负数*//*
					map.put("jd", true);
					map.put("km", "ljdh");
					
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}*/
			
			/*礼券超期未兑换*/
			/*List<Map<String,Object>> overdueCouponMap = courseService.findOverdueCouponK3(enterDateStr);
			if(overdueCouponMap != null && overdueCouponMap.size()>0){
				for(Map<String,Object> map : overdueCouponMap){
					*//**jd 表示收入为true  全部为正数   否则为负数*//*
					map.put("jd", true);
					map.put("km", "ljgq");
					
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}*/
			/*商品销售*/
			/**销售  银行卡 和 现金*/
			List<Map<String,Object>> saleCommodCardMap = courseMapper.getSaleCommodityK3Card(enterDateStr);
			List<Map<String,Object>> saleCommodCashMap = courseMapper.getSaleCommodityK3Cash(enterDateStr);
			/**合并*/
			if(saleCommodCardMap != null && saleCommodCardMap.size() > 0){
				saleCommodCashMap.addAll(saleCommodCashMap);
			}
			
			
			if(saleCommodCashMap != null && saleCommodCashMap.size()>0){
				for(Map<String,Object> map : saleCommodCashMap){
					/**jd 表示收入为true  全部为正数   否则为负数*/
					map.put("jd", true);
					map.put("km", "spxs");
					
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}
			/**退货  银行卡 和 现金*/
			List<Map<String,Object>> returnCommodCardMap = courseMapper.getReturnCommodityK3Card(enterDateStr);
			List<Map<String,Object>> returnCommodCashMap = courseMapper.getReturnCommodityK3Cash(enterDateStr);
			/**合并*/
			if(returnCommodCardMap != null && returnCommodCardMap.size() > 0){
				returnCommodCashMap.addAll(returnCommodCashMap);
			}
			if(returnCommodCashMap != null && returnCommodCashMap.size()>0){
				for(Map<String,Object> map : returnCommodCashMap){
					/**jd 表示收入为true  全部为正数   否则为负数*/
					map.put("jd", false);
					map.put("km", "spth");
					
					k3Income(kde, kdeVRList, kdeEntList, kdeVerPrdList,kdeVerPaymentList, map);
				}
			}
			
			/**批量处理保存数据*/
			if(kdeVRList.size() > 0 && kdeEntList.size() > 0){
				//vrMapper.insertBatchKdeVoucherRecEntity(kdeVRList);
				//vrMapper.insertBatchKdeVoucherEntEntity(kdeEntList);
				vrMapper.insertBatchVrePrd(kdeVerPrdList);
				vrMapper.insertBatchVrePayment(kdeVerPaymentList);
			}
			
		}
		return kde;
	}

	/**
	 *  收入分类
	 * @param kde
	 * @param kdeVRList
	 * @param kdeEntList
	 * @param kdeVerPrdList
	 * @param kdeVerPaymentList
	 * @param map
	 * @throws RDPException 
	 * @date: 2014年10月31日
	 */
	private void k3Income(KdeBatchEntity kde,
			List<KdeVoucherRecEntity> kdeVRList,
			List<KdeVoucherEntEntity> kdeEntList,
			List<KdeVerPrdAndPaymentEntity> kdeVerPrdList,
			List<KdeVerPrdAndPaymentEntity> kdeVerPaymentList,
			Map<String, Object> map) throws RDPException {
		/**对接凭证字  内码*/
		KdeVoucherRecEntity recEntity = null;
		
		
		String voucherType = K3Util.getVoutype((String) map.get("km"));
		//退款获取  凭证码   订单 + 凭证分类(单次票，礼券，课程等等tab类型) 
		recEntity = vrMapper.getByKdeVocherRecWhereOrderIdAndVocherType((String)map.get("PK_ORDER_ID"),voucherType);
		if(recEntity == null){
			recEntity = new KdeVoucherRecEntity();
			recEntity.setFkKdebtId(kde.getPkKdebtId());
			recEntity.setFkVoutypeId(voucherType);
			setKdeVoucherRecEntity(recEntity);
			/**对接凭证字*/
			k3DockVorche(kde, kdeVRList, map, recEntity);
			
			/**保存  对接凭证记录表*/
			vrMapper.insertBatchKdeVoucherRecEntity(recEntity);
		}
		
		/**凭证字  ID*/
		int k3Fvoucherid = recEntity.getK3FvoucherId();
		
		/*获取科目*/
		/**特殊情况判断  （课程签到、）*/
		if(voucherType.equals("kc-qd") ){
			//总价格
			double sumPrice = Double.parseDouble((String)map.get("DIS_PRICE"));
			//总课程数
			int sumKc = Integer.parseInt((String)map.get("CNT"));
			//签到次数
			int signNum = Integer.parseInt((String)map.get("signNum"));
			//单价
			double kcPrice = (sumPrice/sumKc) * signNum;
			
			map.put("km30", "kc-qd30");
			map.put("DIS_PRICE", kcPrice*0.3);
			/**配置借贷信息    及  凭证字关联付款*/
			k3VoucherEntSetting(kde, kdeEntList, kdeVerPrdList, kdeVerPaymentList, map, k3Fvoucherid);
		
			map.put("DIS_PRICE", kcPrice*0.7);
			map.put("km70", "kc-qd70");
			/**配置借贷信息    及  凭证字关联付款*/
			k3VoucherEntSetting(kde, kdeEntList, kdeVerPrdList, kdeVerPaymentList, map, k3Fvoucherid);
			
		}else if(voucherType.equals("kc-gq")){
			//总价格
			double sumPrice = Double.parseDouble((String)map.get("DIS_PRICE"));
			//总课程数
			int sumKc = Integer.parseInt((String)map.get("CNT"));
			//签到次数
			int signNum = Integer.parseInt((String)map.get("signNum"));
			//收入 = （单价=（总金额/课程总数））* （总课程-签到次数） 
			double kcPrice = (sumPrice/sumKc) * (sumKc-signNum);
			
			map.put("DIS_PRICE", kcPrice);
			/**配置借贷信息    及  凭证字关联付款*/
			k3VoucherEntSetting(kde, kdeEntList, kdeVerPrdList, kdeVerPaymentList, map, k3Fvoucherid);
			
		}else{
			/**配置借贷信息    及  凭证字关联付款*/
			k3VoucherEntSetting(kde, kdeEntList, kdeVerPrdList, kdeVerPaymentList, map, k3Fvoucherid);
		}
		
	}

	/***
	 *   处理   凭证字  
	 * @param kde
	 * @param kdeVRList
	 * @param map
	 * @param recEntity
	 * @date: 2014年10月31日
	 */
	private void k3DockVorche(KdeBatchEntity kde,
			List<KdeVoucherRecEntity> kdeVRList, Map<String, Object> map,
			KdeVoucherRecEntity recEntity) {
		/*凭证分类编号，关联KDE_C_VOUTYPE表*/
		recEntity.setFkVoutypeId("1");
		recEntity.setFkKdebtId(kde.getPkKdebtId());
		recEntity.setFkOrderId((String)map.get("PK_ORDER_ID"));
		
		/*K3：凭证字   关联外表    K3：凭证字，现金或银行，在t_VoucherGroup中查找对应记录编号   未确定  暂不定义*/
		recEntity.setK3Fgroupid(0);
		/*附件张数*/
		String payMethod = (String)map.get("PAY_METHOD");
		int fgriupId = 0;
		if(StringUtils.isNotBlank(payMethod)){
			fgriupId = Integer.parseInt(payMethod)==3?2:1 ;
		}
		
		recEntity.setK3Fattachments(fgriupId);
		
		/**K3：凭证序号        每次修改自动增在*/
		recEntity.setK3Fserialnum(0);
		/**K3：凭证号            固定*/
		recEntity.setK3Fnumber(100);
		kdeVRList.add(recEntity);
	}

	/**
	 * 借贷方数据
	 * 
	 * 价格  DIS_PRICE， 会员  FK_MEM_ID，  订单详情  PK_ORDPRD_ID，付款id PK_PAYMENT_ID
	 * @param kde
	 * @param kdeEntList
	 * @param kdeVerPrdList
	 * @param kdeVerPaymentList
	 * @param map
	 * @param k3Fvoucherid
	 * @throws RDPException 
	 * @date: 2014年10月31日
	 */
	private void k3VoucherEntSetting(KdeBatchEntity kde,
			List<KdeVoucherEntEntity> kdeEntList,
			List<KdeVerPrdAndPaymentEntity> kdeVerPrdList,
			List<KdeVerPrdAndPaymentEntity> kdeVerPaymentList,
			Map<String, Object> map, int k3Fvoucherid) throws RDPException {
			
			Object objPrice = map.get("DIS_PRICE");
			if(objPrice != null){
				String disPrice = objPrice.toString();
				/*验证是否是退款*/
				Object flag = map.get("jd");
				double price =0.0;
				if(flag != null ){
					price = Float.valueOf(disPrice);
				}else{
					price = 0 - Float.valueOf(disPrice);
				}
				
				/*借方*/
				KdeVoucherEntEntity jEnt = new KdeVoucherEntEntity();
				/**K3:凭证内码  主键*/
				jEnt.setFkK3FvoucherId(k3Fvoucherid);
				/**批次ID*/
				jEnt.setFkKdebtId(kde.getPkKdebtId());
				/**K3：分录号自动增在ID   K3_FENTRY_ID*/
				/**K3：科目  关联外表  ？？ 暂时未确定   为1  根据不同map - km key 操作不同数据  编号不相同  借方科目编号*/
				jEnt.setK3FaccountId(1);
				
				/**K3：余额方向，借贷方向1-借方 -1 –贷方*/
				jEnt.setK3Fdc(1);
				/**K3：本位币金额 价格*/
				jEnt.setK3Famount(price);
				/*摘要   客户ID*/
				jEnt.setK3Fexplanation((String)map.get("FK_MEM_ID"));
				
				kdeEntList.add(jEnt);
				
				/*贷方*/
				KdeVoucherEntEntity dEnt = new KdeVoucherEntEntity();
				/**K3:凭证内码*/
				dEnt.setFkK3FvoucherId(k3Fvoucherid);
				/**批次ID*/
				dEnt.setFkKdebtId(kde.getPkKdebtId());
				/**K3：分录号自动增在ID   K3_FENTRY_ID*/
				/**K3：科目  关联外表 ？？ 暂时未确定   为1  根据不同map - km key 操作不同数据  编号不相同  贷方科目编号*/
				dEnt.setK3FaccountId(1);
				/**K3：余额方向，借贷方向1-借方 -1 –贷方*/
				dEnt.setK3Fdc(-1);
				/**K3：本位币金额 价格*/
				dEnt.setK3Famount(price);
				/*摘要   客户ID*/
				dEnt.setK3Fexplanation((String)map.get("FK_MEM_ID"));
				
				//kdeEntList.add(dEnt);
				/**保存对接凭证记录*/
				vrMapper.insertBatchKdeVoucherEntEntity(dEnt);
				vrMapper.insertBatchKdeVoucherEntEntity(jEnt);
				
				/*设置关联*/
				String pkOrdPrdId = (String)map.get("PK_ORDPRD_ID");
				int jk3FentryId = jEnt.getK3FentryId();
				int dk3FentryId = dEnt.getK3FentryId();
				
				/**借贷关系*/
				kdeVerPrdList.add(new KdeVerPrdAndPaymentEntity(pkOrdPrdId,jk3FentryId,"",0));
				kdeVerPrdList.add(new KdeVerPrdAndPaymentEntity(pkOrdPrdId,dk3FentryId,"",0));
				
				
				/**设置关联关系*/
				kdeVerPaymentList.add(new KdeVerPrdAndPaymentEntity("",0,(String)map.get("PK_PAYMENT_ID"),k3Fvoucherid));
			
			}
		}
	
	private void setKdeVoucherRecEntity(KdeVoucherRecEntity recEntity){
		/**同步状态 =0 未启动 =1 完成'*/
		recEntity.setSyncStatus("0");
		/**同步结果  =0 失败 =1 成功' 不设置 默认未处理*/
		/**同步时间  暂不设置，未确定*/
		/**K3:凭证内码 暂不设置 系统自动增长*/
		
		/*凭证日期 、 业务日期*/
		recEntity.setK3Fdate(new Date());
		recEntity.setK3Ftransdate(new Date());
		
		
	}

	@Override
	public String isK3Confirm() throws RDPException {
		Date dbDate = kdeBatchEntityMapper.getMaxDateKdeBatch();
		String crrentDate = null;
		if(ObjectUtil.isNotNull(dbDate)){
			Date newDate = DateUtil.addDay2Date(1, dbDate);
			Date sysDate = new Date();
			if(!(newDate.getTime() >= sysDate.getTime())){
				crrentDate = DateUtil.formatDate("yyyy-MM-dd", newDate);
			}
		}
		return crrentDate;
	}

	public List<Map<String, Object>> findPartyUpdate(String date)
			throws RDPException {
		return vrMapper.findPartyUpdate(date);
	}
	public List<Map<String, Object>> findCancelRes(String date)
			throws RDPException {
		List<Map<String, Object>> list=vrMapper.findCancelRes(date);
		if(list==null||list.get(0)==null){
			return null;
		}else{
			return list;
		}
	}
	public List<Map<String, Object>> findCompletedRes(String date)
			throws RDPException {
		List<GblScmPrdCateEntity> cateList=productService.recurseCate(Constants.PRDCATE_ORNAMENT, true, true);
		return vrMapper.findCompletedRes(date,cateList);
	}

	@Override
	public KdeBatchEntity findByIdOrDateKdeBatch(String batchId,String confiDate) throws RDPException {
		return kdeBatchEntityMapper.getByIdOrDateKdeBatch(batchId, confiDate);
	}

	@Override
	public void updateKdeBatchEntity(KdeBatchEntity kde) throws RDPException {
		kdeBatchEntityMapper.updateKdeBatchEntity(kde);
	}

	@Override
	public List<KdeBatchEntity> getKdeBatchListWhere(KdeBatchEntity kdeBatch)
			throws RDPException {
		return kdeBatchEntityMapper.getKdeBatchList(kdeBatch);
	}

	@Override
	public void updateKdeVoucherRecEntity(KdeVoucherRecEntity recEntity)throws RDPException {
		vrMapper.updateKdeVoucherRecEntity(recEntity);
	}

	@Override
	public List<Map<String, Object>> findK3RecSynchronousData(KdeVoucherRecEntity recEntity) throws RDPException {
		return vrMapper.getK3RecSynchronousData(recEntity);
	}

	@Override
	public List<Map<String, Object>> findK3EntSynchronousData( KdeVoucherEntEntity kdeVoucherEntEntity) throws RDPException {
		return vrMapper.getK3EntSynchronousData(kdeVoucherEntEntity);
	}

	@Override
	public void updateBatchKdeVoucherEntEntity(KdeVoucherEntEntity kdeVoucherEntEntity) throws RDPException {
		vrMapper.updateBatchKdeVoucherEntEntity(kdeVoucherEntEntity);
	}
}
